//
//  VideoTitleCell.swift
//  SafeFoodManagerDemo
///Users/keelon/Downloads/SafeFoodManagerDemo  4/SafeFoodManagerDemo/Classes/Study/View/Cell/VideoTitleCell.swift
//  Created by 振轩 on 2018/4/25.
//  Copyright © 2018年 bob. All rights reserved.
//

import UIKit

class VideoTitleCell: UITableViewCell {

    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var subTitleLabel: UILabel!
    @IBOutlet weak var likeBTN: UIButton!
    @IBOutlet weak var collectBTN: UIButton!
    @IBOutlet weak var collectCountLabel: UILabel!
    
    @IBOutlet weak var ViewCountLabel: UILabel!
    
    @IBOutlet weak var likeCountLabel: UILabel!
    
    
    
    
    var mode:ArticleDetail?{
        
        didSet{
            if mode != nil {
                
                titleLabel.text = mode?.title
                if mode?.isLike == 0 {
                    likeBTN.setImage(UIImage.init(named: "dz"), for: .normal)
                }else{
                    likeBTN.setImage(UIImage.init(named: "dz2"), for: .normal)
                }
                subTitleLabel.text = mode?.intro
                collectCountLabel.text = "\(String(describing: mode!.collectNum))"
                likeCountLabel.text = "\(String(describing: mode!.likeNum))"
                if mode?.isCollect == 0 {
                    collectBTN.setImage(UIImage.init(named: "sc2"), for: .normal)
                }else{
                    collectBTN.setImage(UIImage.init(named: "sc"), for: .normal)
                    
                }
                //likeCountLabel.text = "\(mode!.isLike)";
                ViewCountLabel.text = "\(mode!.viewNum)"+"次播放"
                
            }
        }
    }
    
    
    
    
    
    
    @IBAction func collectTap(_ sender: Any) {
        
         loadRefresh(url: "/index.php/FoodCheckApi/courseCollect.json",isLike: false)
    }
    @IBAction func LickClick(_ sender: Any) {
        
        
        loadRefresh(url: "/index.php/FoodCheckApi/courseLike.json", isLike: true)
        
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        
        // Initialization code
        
        
        
    }
    
    
    
    
    func loadRefresh(url:String,isLike:Bool){
        
        
        var params = [String:AnyObject]()
        params["courseId"] = mode?.id as AnyObject
        
        params["staffId"] = LoginStatuesModel.getStaffId() as AnyObject
        params["staffType"] = LoginStatuesModel.getUserType() as AnyObject
        let API:BaseReqApi = BaseReqApi.init(requestUrl: url, andrequestTime: 5, andParams: params as! [AnyHashable : Any], andRequestMethod: YTKRequestMethod.POST, andCache: false, andCacheTime: 0, andPostToken: true)
        API.starRequest { (status, mess, response) in
            
            guard let dic:Dictionary = response as? [String : AnyObject] else{
                
                return
            }
            print("_______***______")
            print(dic)
            print("_______***______")
            let Dir:[String:NSObject] = dic["data"] as! [String : NSObject]
            //let mode1  = CourseDetail.init(DIC: dic)
            if isLike{
                
                
                
                let mode1 :ArticleDetail = self.mode!
                
                mode1.isLike = Dir["isLike"] as! NSInteger
                mode1.likeNum = Dir["total"] as! NSInteger
                self.mode = mode1
                
                
            }else{
                
                let mode1 :ArticleDetail = self.mode!
                
                mode1.isCollect = Dir["isCollect"] as! NSInteger
                mode1.collectNum = Dir["total"] as! NSInteger
                
                self.mode = mode1
                
            }
            
        }
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
